import re

# 定义正则表达式模式
pattern = r'.*posture:\[(?P<posture>[^]]+)\].*bodyJoint:\[(?P<bodyJoint>[^]]+)\].*extJoint:\[(?P<extJoint>[^]]+)\]'

# 源文件路径和目标文件路径
source_file_path = 'E:/crp_linux_e/build_windows/bin/bin/Debug/log/MotionTrace.txt'
target_file_path = 'E:/crp_linux_e/build_windows/bin/bin/Debug/log/MotionTrace1.txt'

# 读取源文件
with open(source_file_path, 'r', encoding='utf-8') as file:
    lines = file.readlines()

# 创建或打开目标文件以写入结果
with open(target_file_path, 'w', encoding='utf-8') as target_file:
    # 遍历每一行
    for line in lines:
        # 使用正则表达式匹配并提取值
        match = re.search(pattern, line)
        if match:
            aaa = match.group('posture')
            bbb = match.group('bodyJoint')
            ccc = match.group('extJoint')
            
            # 写入提取的值
            target_file.write(f"{aaa},{bbb},{ccc}\n")
